﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using _1061102_1061114_1061129_1061132_1061141.Models;
using PagedList;
using BanDTBLL;

namespace _1061102_1061114_1061129_1061132_1061141.Controllers
{
    public class SanPhamController : Controller
    {
        //
        // GET: /SanPham/

        ban_dien_thoai_dbEntities storeDB = new ban_dien_thoai_dbEntities();

        public ActionResult Index(int? page)
        {
            var list = storeDB.san_pham.Where(a => a.trangThai != 5).OrderBy(a => a.ma);

            int pageSize = 4;
            int pageNumber = (page ?? 1);
            return View(list.ToPagedList(pageNumber, pageSize));
        }

        public ActionResult Detail(int id)
        {
            var detail = storeDB.san_pham.Where(a=> a.ma == id && a.trangThai != 5).FirstOrDefault();

            return View(detail);
        }

        public ActionResult TheoLoaiSanPham(int id, int? page)
        {
            var list = storeDB.san_pham.Where(a => a.trangThai != 5 && a.maLoaiSP == id).OrderBy(a => a.ma);

            int pageSize = 2;
            int pageNumber = (page ?? 1);
            return View(list.ToPagedList(pageNumber, pageSize));
        }

        public ActionResult ListLoaiSanPham()
        {
            var list = storeDB.loai_san_pham.OrderBy(a => a.ma);

            return PartialView(list);
        }
    
    }
}
